import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

export const constantRoutes = [
  {
    path: "/login",
    name:"Login",
    component: () => import("@/views/login/index"),
    hidden: true
  },

  {
    path: "/404",
    name: "404",
    component: () => import("@/views/404"),
    hidden: true
  },

  {
    path: "/",
    component: Layout,
    redirect: "/home",
    children: [
      {
        path: "home",
        name: "Home",
        component: () => import("@/views/home/index"),
        meta: { title: "首页", icon: "el-icon-s-home" }
      }
    ]
  },

  {
    path: "/acl",
    component: Layout,
    redirect: "/acl/user/list",
    name: "Acl",
    meta: { title: "权限管理", icon: "el-icon-setting" },
    children: [
      {
        path: "/acl/user/list",
        name: "User",
        component: () => import("@/views/acl/user/index.vue"),
        meta: { title: "用户管理"}
      },
      {
        path: "/acl/role/list",
        name: "Role",
        component: () => import("@/views/acl/role/index.vue"),
        meta: { title: "角色管理" }
      },
      {
        name:"RoleAuth",
        path:"/acl/role/auth",
        component:()=>import("@/views/acl/role/roleAuth.vue"),
        mata:{
          title:"角色管理111",
          hidden: true,
          activeMenu: "/acl/role/list",
        }
      }
    ]
  },
  {
    path: "/product",
    name: "Product",
    component: Layout,
    redirect: "/product/trademark/list",
    meta: {    title: "商品管理",icon:"el-icon-s-shop"},
    children: [
      {
        name: "Trademark",
        path: "trademark/list",
        component: () => import("@/views/product/trademark/index.vue"),
        meta: {
          title: "品牌管理",
        },
      },
      {
        name: "Category",
        path: "category/list",
        component: () => import("@/views/product/category/index.vue"),
        meta: {
          title: "分类管理",
        },
      },
    ]
  },
  // 404 page must be placed at the end !!!
  { path: "*", redirect: "/404", hidden: true }
];

const createRouter = () =>
  new Router({
     mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  });

const router = createRouter();

export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
